const {
  kind
} = require('../models/index')
const _ = require('lodash')
const errorHelper = require('../util/errorHelper')

class KindController {
  constructor() {
    // empty
  }
  async createKind(kinds) {
    const result = await kind.bulkCreate(kinds)
    if (!result.length) {
      throw errorHelper(400, 'post data error')
    }
    return result
  }

  async delete(kinds) {
    // for (let i = 0; i < goods.length; i++) {
    //   // eslint-disable-next-line
    //   await good.destroy({ where: goods[i] })
    // }
    const promiseArr = []
    _.forEach(kinds, async (item) => {
      promiseArr.push(await kind.update({
        disable: true
      }, {
        where: item
      }))
    })
    return Promise.all(promiseArr).then((data) => {
      return true
    })
  }
}
module.exports = new KindController()